﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Windows.Media.Imaging;

namespace Sapro_Project
{
    public partial class ListEsc : PhoneApplicationPage
    {
        List<Grid> nomesEsc = new List<Grid>();
        public ListEsc()
        {
            InitializeComponent();
        }
        private void ContentPanel_Loaded(object sender, RoutedEventArgs e)
        {
            foreach (Escola esc in Fachada.ObterFachada().BuscaEscola())
            {
                TextBlock nome = new TextBlock();
                Button excEsc = new Button();
                Button editEsc = new Button();
                Grid ret = new Grid();
                #region texto
                    nome.MouseLeftButtonDown += delegate(object ob, MouseButtonEventArgs c)
                    {
                        Color cor = new Color();
                        cor.R = 44;
                        cor.G = 90;
                        cor.B = 160;
                        cor.A = 200;
                        ret.Background = new SolidColorBrush(cor);
                        nome.Foreground = new SolidColorBrush(Colors.White);

                    };
                    nome.MouseLeftButtonUp += delegate(object ob, MouseButtonEventArgs c)
                    {
                        ret.Background = new SolidColorBrush(Colors.Transparent);
                        nome.Foreground = new SolidColorBrush(Colors.Black);
                        NavigationService.Navigate(new Uri("/ListMateria.xaml", UriKind.RelativeOrAbsolute));
                    };
                    nome.MouseMove += delegate(object ob, MouseEventArgs c)
                    {
                        nome.Foreground = new SolidColorBrush(Colors.Black);
                        ret.Background = new SolidColorBrush(Colors.Transparent);
                    };
                    nome.MouseLeave += delegate(object ob, MouseEventArgs c)
                    {
                        nome.Foreground = new SolidColorBrush(Colors.Black);
                        ret.Background = new SolidColorBrush(Colors.Transparent);
                    };
                    Thickness tk0 = new Thickness();
                    tk0.Top = 18;
                    tk0.Left = 18;
                    nome.Margin = tk0;
                    nome.FontSize = 26.667;
                    nome.Foreground = new SolidColorBrush(Colors.Black);
                    nome.Text = "" + esc.Nome;
                #endregion
                #region edit_button
                editEsc.Content = "";
                    editEsc.BorderBrush = new SolidColorBrush(Colors.Transparent);
                    editEsc.Width = 75;
                    editEsc.Height = 75;
                    Thickness tk = new Thickness();
                    tk.Left = 234;
                    tk.Top = 2;
                    editEsc.Margin = tk;
                    ImageBrush imEd = new ImageBrush();
                    imEd.ImageSource = new BitmapImage(new Uri(@"images/edit.png", UriKind.Relative));
                    editEsc.Background = imEd;
                    editEsc.GotFocus += delegate(object ob, RoutedEventArgs c)
                    {
                        editEsc.BorderBrush = new SolidColorBrush(Colors.Transparent);
                        ImageBrush imEx2 = new ImageBrush();
                        imEx2.ImageSource = new BitmapImage(new Uri(@"images/edit_pressed.png", UriKind.Relative));
                        editEsc.Background = imEx2;
                    };
                    editEsc.LostFocus += delegate(object ob, RoutedEventArgs c)
                    {
                        ImageBrush imEx2 = new ImageBrush();
                        imEx2.ImageSource = new BitmapImage(new Uri(@"images/edit.png", UriKind.Relative));
                        editEsc.Background = imEx2;
                    };
                    editEsc.MouseLeave += delegate(object ob, MouseEventArgs c)
                    {
                        ImageBrush imEx2 = new ImageBrush();
                        imEx2.ImageSource = new BitmapImage(new Uri(@"images/edit.png", UriKind.Relative));
                        editEsc.Background = imEx2;
                    };
                    editEsc.Click += delegate(object s, RoutedEventArgs ev)
                    {
                        MessageBoxResult result = MessageBox.Show("Deseja editar?", "Editar", MessageBoxButton.OKCancel);
                        if (result == MessageBoxResult.OK)
                        {
                            NavigationService.Navigate(new Uri("/PhonePageCadEsc.xaml?nome="+esc.Nome+"", UriKind.RelativeOrAbsolute));
                        }
                    };
                #endregion
                #region exc_button
                    excEsc.Content = "";
                    excEsc.BorderBrush = new SolidColorBrush(Colors.Transparent);
                    excEsc.CommandParameter = 1;
                    excEsc.Width = 75;
                    excEsc.Height = 75;
                    Thickness tk2 = new Thickness();
                    tk2.Left = 354;
                    tk2.Top = 2;
                    excEsc.Margin = tk2;
                    ImageBrush imEx = new ImageBrush();
                    imEx.ImageSource = new BitmapImage(new Uri(@"images/exc.png", UriKind.Relative));
                    excEsc.Background = imEx;
                    String nm = esc.Nome;
                    excEsc.GotFocus += delegate(object ob, RoutedEventArgs c)
                    {
                        excEsc.BorderBrush = new SolidColorBrush(Colors.Transparent);
                        ImageBrush imEx2 = new ImageBrush();
                        imEx2.ImageSource = new BitmapImage(new Uri(@"images/exc_pressed.png", UriKind.Relative));
                        excEsc.Background = imEx2;
                    };
                    excEsc.LostFocus += delegate(object ob, RoutedEventArgs c)
                    {
                        ImageBrush imEx2 = new ImageBrush();
                        imEx2.ImageSource = new BitmapImage(new Uri(@"images/exc.png", UriKind.Relative));
                        excEsc.Background = imEx2;
                    };
                    excEsc.MouseLeave += delegate(object ob, MouseEventArgs c)
                    {
                        ImageBrush imEx2 = new ImageBrush();
                        imEx2.ImageSource = new BitmapImage(new Uri(@"images/exc.png", UriKind.Relative));
                        excEsc.Background = imEx2;
                    };
                    excEsc.Click += delegate(object s, RoutedEventArgs ev)
                    {
                        MessageBoxResult result= MessageBox.Show("Deseja excluir "+nm+"?", "Excluir",MessageBoxButton.OKCancel);
                        if (result == MessageBoxResult.OK)
                        {
                            MessageBox.Show("Valeu");
                        }
                        else { MessageBox.Show("Não Valeu"); }
                    };
                #endregion
                ret.Width = 430;
                ret.Children.Add(nome);
                ret.Children.Add(editEsc);
                ret.Children.Add(excEsc);
                nomesEsc.Add(ret);
            }
            list_escola.ItemsSource = nomesEsc;
        }

        private void cad_escola_GotFocus(object sender, RoutedEventArgs e)
        {
            cad_escola.BorderBrush = new SolidColorBrush(Colors.Transparent);
            ImageBrush imEx2 = new ImageBrush();
            imEx2.ImageSource = new BitmapImage(new Uri(@"images/novo_cad_pressed.png", UriKind.Relative));
            cad_escola.Background = imEx2;
        }

        private void cad_escola_LostFocus(object sender, RoutedEventArgs e)
        {
            ImageBrush imEx2 = new ImageBrush();
            imEx2.ImageSource = new BitmapImage(new Uri(@"images/novo_cad.png", UriKind.Relative));
            cad_escola.Background = imEx2;
        }

        private void cad_escola_MouseLeave(object sender, MouseEventArgs e)
        {
            ImageBrush imEx2 = new ImageBrush();
            imEx2.ImageSource = new BitmapImage(new Uri(@"images/novo_cad.png", UriKind.Relative));
            cad_escola.Background = imEx2;
        }
    }
}
